<template>
  <div>
    <el-row type="flex">
      <el-col>
        <el-table
          :data="tableSetting.data"
          border
          style="width: 100%;"
          :cell-style="setAlign"
          :header-cell-style="setTableHeader"
        >
          <el-table-column
            v-for="(item, index) in tableSetting.column"
            :key="index"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
          ></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                :disabled="!(authority.canOperatePlan)"
                size="mini"
                type="primary"
                plain
                @click="modifyPlan(scope.$index, scope.row)"
              >修改</el-button>
              <el-button
                :disabled="!(authority.canOperatePlan)"
                size="mini"
                type="danger"
                plain
                @click="deletePlan(scope.$index, scope.row)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { deleteVersionPlan } from "@/service/progressApi";

import bus from "@/components/bus";

export default {
  name: "progressTable",
  props: ["tableSetting", "authority"],
  data() {
    return {};
  },
  methods: {
    setAlign() {
      return { textAlign: "center" };
    },
    setTableHeader() {
      return { backgroundColor: "#F9F9F9", textAlign: "center" };
    },
    modifyPlan(index, row) {
      this.$emit("modifyPlan", "修改计划", row);
    },
    deletePlan(index, row) {
      this.$confirm("此操作将永久删除该计划, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          deleteVersionPlan(row.id).then((res) => {
            if (res.code === 0) {
              this.$message.success("删除成功!");
              this.$emit("verPlanListData");
            } else {
              this.$message.warning(res.message);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style scoped>
</style>